package com.j1ay.forum.controller;

import com.j1ay.forum.service.UploadSerive;
import com.j1ay.forum.utils.QiniuUtils;
import com.j1ay.forum.model.pojo.vo.Result;
import com.j1ay.forum.model.pojo.vo.UploadVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.UUID;

/**
 * @Author J1ay
 * @Date 2021/12/17 18:49
 * @Description 文件上传
 */

@RestController
@RequestMapping("api")
@Api(value = "Upload Controlller", tags = {"文件上传"})
public class UploadControlller {

    @Autowired
    private UploadSerive uploadSerive;

    @ApiOperation("更新头像")
    @PostMapping("upload/image")
    public Result upload(@RequestParam("image") MultipartFile file, @RequestParam("userId") Long userId) {
        return uploadSerive.uploadImg(file, userId);
    }

    @ApiOperation("上传图片到七牛云")
    @PostMapping("upload/mdImg")
    public Result uploadMdImg(@RequestParam("images") MultipartFile file) {
        return uploadSerive.uploadMdImg(file);
    }

    @PostMapping("download/{filename}")
    public Result downLoad(@PathVariable("filename") String filename) {
        return uploadSerive.downLoad(filename);
    }


}
